<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>当前站点首页生成</title>
	<%@ include file="/common/meta.jsp"%>
	<%@ include file="/common/common.jsp"%>
	<script type="text/javascript" src="${ctx}/js/jquery.progressbar2.js"></script>
	<script type="text/javascript" src="${ctx}/js/publish.js"></script>
 
</head>
<body>
<s:set name="siteId" value="#session['CURRENT_SITE'].siteId"></s:set>
	<form name="publish_form">
	<s:hidden name="site.siteId"/>
	<s:hidden name="percentKey"/>
<div id="wrapper">
	<div class="curmb">您现在的位置：<a href="${ctx}/main.action">首页</a><span>></span><a href="#">发布管理</a></div>
	<div class="listtit" id="listtit"><p><span><strong>发布</strong><s:if test="site!=null">--当前站点--<font color="red"><s:property value="site.siteName"/></font></s:if></span></p></div>
	<div class="listoperate whitebg" id="listoperate">
		<span class="space20"></span>
			<a href="#" class="alinks" onclick="publishAll()">全站</a>|
			<a href="#" class="alinkscurrent" onclick="publishCat()">栏目</a>|
			<a href="#" class="alinks" onclick="publishTopic()">专题</a>|
			<a href="#" class="alinks" onclick="publishSurvery()">调查</a>|
			<a href="#" class="alinks" onclick="publishAssociator()">协会理事会</a>
	</div>
	<div class="issuecheck">
		<s:if test="%{authLicence('2_2_6',#siteId)}">
			<input type="radio" name="website" checked="checked" value="all" /><label>全量</label>
			<input type="radio" name="website" value="more"/><label>增量</label>
			<input type="radio" name="website" value="index"/><label>只发布首页、列表页</label>
			<!-- <input type="radio" name="website" value="list"/><label>只发列表页面</label> -->
		</s:if>
		<s:elseif test="%{authLicenceLike('3_3_2')}">
			<input type="radio" name="website" checked="checked" value="all" /><label>全量</label>
			<input type="radio" name="website" value="more"/><label>增量</label>
			<input type="radio" name="website" value="index"/><label>只发布首页、列表页</label>
			<!-- <input type="radio" name="website" value="list"/><label>只发列表页面</label> -->
		</s:elseif>
		<s:else>
			<input type="radio" name="website" value="all" disabled="disabled"/><label>全量</label>
			<input type="radio" name="website" value="more" disabled="disabled"/><label>增量</label>
			<input type="radio" name="website" value="index" disabled="disabled"/><label>只发布首页、列表页</label>
			<!-- <input type="radio" name="website" value="list" disabled="disabled"/><label>只发列表页面</label> -->
		</s:else>
	</div>
	<div class="listoperateb ">
		<span>
			<s:if test="%{authLicence('2_2_6',#siteId)}">
				<input type="button" value="全选"  class="btnlist2" id="checkAll"/>
				<input type="button" value="反选"  class="btnlist2" id="anti"/>
				<input type="button" value="发布" class="btnsave2" id="publish"/>
				<input type="button" value="查询详细"  class="btnlist4" id="detail"/>
			</s:if>
			<s:elseif test="%{authLicenceLike('3_3_2')}">
					<input type="button" value="全选"  class="btnlist2" id="checkAll"/>
					<input type="button" value="反选"  class="btnlist2" id="anti"/>
					<input type="button" value="发布" class="btnsave2" id="publish"/>
					<input type="button" value="查询详细"  class="btnlist4" id="detail"/>
			</s:elseif>
			<s:else>
				<input type="button" value="全选"  class="btnlist2" id="checkAll" disabled="disabled"/>
				<input type="button" value="反选"  class="btnlist2" id="anti" disabled="disabled"/>
				<input type="button" value="发布" class="btnsave2" id="publish" disabled="disabled"/>
				<input type="button" value="查询详细"  class="btnlist4" id="detail" disabled="disabled"/>
			</s:else>
			<label id="info"></label>
		</span>
	</div>
	<div class="listbox" id="listbox">
	<table class="listgrid" id="listtable">
		<tbody>
			<tr>
				<th>栏目选择</th>
				<th style="width: 90%">详细信息</th>
			</tr>
			<tr>
				<td style="height: 100%;text-align: left;">
			 		<div id="treeDiv_PublishCat" class="ztree" style="overflow-y:auto;overflow-x:auto;height:300px;width:200px"></div>
				</td>
				<td style="width: 90%;height: 100%" id="before">
				<p><span class="issuebg">您还未选择需发布的栏目，<br/>请在左侧栏目列表选择栏目进行详情查看</span></p>
				</td>
				<td style="height: 100%;display: block;" id="after">
					<table class="listgrid" id="listtable">
						<tbody id="content_detail">
							<tr>
								<th>栏目名称</th>
								<th>文章总数</th>
								<th>待发布文章数</th>
								<th>已发布文章数</th>
							</tr>
						</tbody>
					</table>
				</td>
			</tr>
		</tbody>
	</table>
		
	</div>
</div>
</form>
<div id="lightbox_c" class="lightbox" >
	<div class="lighttit"><p><span><input type="button" value="&nbsp;" id="lightclose_c" class="lightclose" /><strong>发布站点</strong></span></p></div>
	<div class="lightmain">
		<div class="lightmaintit"><input type="button" value="错误信息" id="changeInfo" class="btnlist2"/><label id="returnInfo">正在发布栏目....</label>
		</div>
		<div id="progressBar_bg">
			<span class="progressBar" id="pb2"></span>
			<span id="progressBar_bh"></span>
		</div>
		<div align="right"><input type="button" value="隐藏日志" id="hideInfo" class="btnlist2"/>
		</div>
		<div id="publishInfoAll" align="center">
			<textarea rows="10" cols=60 id="pia" readonly="readonly">aaa</textarea>
		</div>
		<div id="publishInfoError" align="center">
			<textarea rows="10" cols=60 id="pie" readonly="readonly">bbb</textarea>
		</div>
		<div class="lightbtnbox mb25"><input type="button" value="确认" id="lightsubmit_c" class="btnlist2"/><input type="button" value="停止" id="stoppublish" class="btnlist2 ml20"/></div>
	</div>
</div>
</body>
</html>
<script type="text/javascript">

	var actionName = '${ctx}';
	var ctx = '${ctx}';
	$("#hideInfo").click(function(){
		if($(this).val()=="隐藏日志"){
			$(this).val("显示日志");
			$("#publishInfoAll").hide();
			$("#publishInfoError").hide();
		}else{
			$(this).val("隐藏日志");
			$("#publishInfoAll").show();
			$("#publishInfoError").hide();
		}
	});
	$("#changeInfo").click(function(){
		if($(this).val()=="错误信息"){
			$(this).val("全部信息");
			$("#hideInfo").val("隐藏日志");
			$("#publishInfoAll").hide();
			$("#publishInfoError").show();
		}else{
			$(this).val("错误信息");
			$("#hideInfo").val("隐藏日志");
			$("#publishInfoAll").show();
			$("#publishInfoError").hide();
		}
	});
	$("#stoppublish").click(function(){
		stopPublish();
	});
	$("#publish").click(function(){
		var catIds = getAllSelectedNodesIds();	
		if(!catIds){
			alert("请选择栏目！");
			return false;
		}		 
		$("#stoppublish").attr("disabled","");
		$$.shade("#publish","#lightclose_c,#lightsubmit_c","#lightbox_c","350");
		publishCats(catIds,$("input[name=website]:checked").val());
	});
	$("#lightclose_c").click(function(){
		initBar();
	});
	$("#lightsubmit_c").click(function(){
		initBar();
	});
	function initBar(){
		$('#pb2').progressBar(0);
	}
	$(document).ready(function (){
		$("#after").hide();
		$("#publish_index").hide();
		$("#publish_more").hide();
		$("#pb2").progressBar({ barImage: '../images/progressbg_yellow2.gif'} );
	});
	$("input[name=website]").click(function(){
		$(this).each(function(){
			if($(this).attr("checked")==true){
				if($(this).val()=="index"){
					$("#publish_all").hide();
					$("#publish_index").show();
					$("#publish_more").hide();
				}
				if($(this).val()=="all"){
					$("#publish_all").show();
					$("#publish_index").hide();
					$("#publish_more").hide();
				}
				if($(this).val()=="more"){
					$("#publish_all").hide();
					$("#publish_index").hide();
					$("#publish_more").show();
				}
			}
		});
		
	});
	function publishAll(){
		$("form[name=publish_form]").attr("action","${ctx}/generate/list-site.action");
		$("form[name=publish_form]").submit();
	}
	function publishCat(){
		$("form[name=publish_form]").attr("action","${ctx}/generate/list-cat.action");
		$("form[name=publish_form]").submit();
	}
	function publishTopic(){
		$("form[name=publish_form]").attr("action","${ctx}/generate/list-topic.action");
		$("form[name=publish_form]").submit();
	}
	function publishSurvery(){
		$("form[name=publish_form]").attr("action","${ctx}/generate/list-survey.action");
		$("form[name=publish_form]").submit();
	}
	 
	$("input[name=cateNameBox]").each(function(){
		$(this).click(function(){
			alert($(this).val());
		});
	});
	$("#checkAll").click(function(){
		 var treeObj = $.fn.zTree.getZTreeObj('treeDiv_PublishCat');
		 treeObj.checkAllNodes(true);		 
	});
	$("#anti").click(function(){
		var treeObj = $.fn.zTree.getZTreeObj('treeDiv_PublishCat');
		var a = treeObj.getNodesByParam('checked',true);
		var b = treeObj.getNodesByParam('checked',false);
		function_anti(a, true, treeObj);
		function_anti(b, false, treeObj);
		 
	});
	
	function function_anti(nodes,flag,treeObj){ 	 
		if(nodes){
			for(var i=0;i<nodes.length;i++){
				if(!flag){
					if(nodes[i].nocheck == false){ 
						nodes[i].checked = !flag;
						treeObj.updateNode(nodes[i]);						
					}
				}else{
					nodes[i].checked = !flag;
					treeObj.updateNode(nodes[i]);
				}
			}
		}
	}
	
	function getAllSelectedNodesIds(){ 
		var treeObj = $.fn.zTree.getZTreeObj('treeDiv_PublishCat');
		var nodes = treeObj.getNodesByParam('checked',true);  
		var arrays = new Array();
		if(nodes){
			for(var i=0;i<nodes.length;i++){ 
				arrays.push(nodes[i].id);
			}
		}
		return arrays.join(',');		
	}
	
	$("#detail").click(function(){  
		var str = getAllSelectedNodesIds();	
		if(!str){
			alert("请选择栏目!");
		}else{
			$("#info").html("正在查询....请稍候");
			$.post("${ctx}/generate/cat-detail.action?catIdTargets="+str,function(data){
				$("#content_detail").html("<tr><th>栏目名称</th><th>文章总数</th><th>待发布文章数</th><th>已发布文章数</th></tr>");
				$("#info").html("");  
				var json = eval('('+data+')');
				var catName = json.catName;
				var contentNum = json.contentNum.split("@");
				var contentSuc = json.contentSuc.split("@");
				var contentPub = json.contentPub.split("@");
				var obj = catName.split("@");
				var str = "";
				for(var i = 0 ; i<obj.length-1 ; i++){
					str+="<tr>";
					str+="<td>"+obj[i]+"</td>";
					str+="<td>"+contentNum[i]+"</td>";
					str+="<td>"+contentSuc[i]+"</td>";
					str+="<td>"+contentPub[i]+"</td>";
					str+="</tr>";
				}
				$("#content_detail").append(str);
				$("#before").hide();
				$("#after").show();
			});
		}
	});
	function publishAssociator(){
		$("form[name=publish_form]").attr("action","${ctx}/generate/list-associator.action");
		$("form[name=publish_form]").submit();
	}
</script>
<link href="${ctx}/css/zTreeStyle/zTreeStyle.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="${ctx}/js/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${ctx}/js/jquery.ztree.excheck-3.0.js"></script>
<script type="text/javascript">
  function loadCatetree (type,needUrl,id){	
	$.ajax({
		async:false, 
		url:"${ctx}/site/sitetree.action?t="+new Date().getTime(),
		data:{"type":type,"needurl":needUrl},
		type:"post",
		dataType:"text",
		success:function(ss){
			var setting = {
					check: {
						enable: true,
						chkStyle: "checkbox",
						chkboxType :{ Y:'s',N:'s'}
					},
					data: {
						simpleData: {
							enable: true
						}
					}
				};

			var zNodes = eval('('+ss+')');
			$.fn.zTree.init($("#"+id), setting, zNodes);
			 
		}
	});
} 	
$(function(){
	loadCatetree(true,false,'treeDiv_PublishCat');
});  
  
</script>